package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.entity.NursingPlan;
import com.zzyl.entity.NursingPlanXZ;
import com.zzyl.service.NursingPlanService;
import com.zzyl.vo.NursingPlanVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing/plan")
@Api(tags = "护理计划")
public class NursingPlanController {
    @Autowired
    private NursingPlanService nursingPlanService;


    @GetMapping
    @ApiOperation("查询所有护理计划")
    public ResponseResult getPlan(){
        List<NursingPlan> list = nursingPlanService.getPlan();
        return success(list);
    }

    @GetMapping("/search")
    @ApiOperation("护理计划分页查询")
    public ResponseResult<PageResponse<NursingPlanVo>> search(@ApiParam(value = "护理项目名称") String name,
                                                                  @ApiParam(value = "当前页") @RequestParam(defaultValue = "1", required = false) Integer pageNum,
                                                                  @ApiParam(value = "每页显示记录数") @RequestParam(defaultValue = "10", required = false) Integer pageSize,
                                                                  @ApiParam(value = "状态")Integer status){
        PageResponse<NursingPlanVo> nursingPlanVo = nursingPlanService.search(name,pageNum,pageSize,status);
        return success(nursingPlanVo);
    }

    @PostMapping
    @ApiOperation("添加护理计划")
    public ResponseResult add(@RequestBody NursingPlanXZ nursingPlanXZ){
        nursingPlanService.add(nursingPlanXZ);
        return success();
    }


    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理计划")
    public ResponseResult<NursingPlanVo> getById(@PathVariable Integer id){
        NursingPlan nursingPlan = nursingPlanService.getById(id);
        return success(nursingPlan);
    }

    @PutMapping("/{id}")
    @ApiOperation("根据id修改护理计划")
    public ResponseResult update(@RequestBody NursingPlanXZ nursingPlanXZ) {
        nursingPlanService.update(nursingPlanXZ);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除护理计划")
    public ResponseResult delete(@PathVariable Integer id){
        nursingPlanService.delete(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult status(Integer id ,
                                          Integer status) {
        nursingPlanService.updateStatusById(id, status);
        return success();

    }
}
